package top.chj.day18.genericity.yinyong1;

import java.text.Collator;
import java.util.Arrays;
import java.util.Locale;

/**
 * @Auther:小陈的Java
 */
public class User3 implements Comparable<User3>{
    private int id;
    private String name;
    private int age;

    public User3() {
    }

    public User3(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User3{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(User3 o) {
        if (o == null){
            throw  new NullPointerException("null不能进行排序");
        }
        if (this.age!=o.getAge()){
            return this.age-o.getAge();
        }else {
            Collator collator = Collator.getInstance(Locale.CHINA);
            return collator.compare(this.name,o.getName());
        }
    }

    public static void main(String[] args) {
        User3[] user3 = new User3[3];
        user3[0] = new User3(1,"张三",19);
        user3[1] = new User3(2,"七七",15);
        user3[2] = new User3(3,"李四",19);
        Arrays.sort(user3);
        System.out.println(Arrays.toString(user3));
    }
}
